package com.firefly.fmt;

import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.text.DecimalFormat;
import java.util.Date;

import javax.swing.JFrame;

import com.firefly.curve.CurvePanel;
import com.firefly.curve.curve.CurveLines;
import com.firefly.curve.listener.CurveMouseListener;

public class FmtMain extends JFrame{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private CurvePanel curve=null;
	private CurveLines lines1=null;
	private CurveLines lines2=null;
	private DecimalFormat decimalFormat = new DecimalFormat("0.00");//刻度值格式
	
	public FmtMain(){
		this.setBounds(0, 0, 600, 400);
		this.setDefaultCloseOperation(3);
		
		Container container=this.getContentPane();
//		container.setLayout(null);
		
		curve=new CurvePanel();
		curve.setShowCross(true);
		curve.getMargin().setTop(60);
		curve.setTitleRight("abcdefghijklmnopqrstuvwxyz你是中国人吗，你好");
		curve.setExplainText("abcdefghijklmnopqrstuvwxyz\n你是中国人吗，你好\n你是中国人吗，你好\nabcdefghijklmnopqrstuvwxyzsssssfdsfd");
		curve.setExplainTextColor(Color.red);
		curve.setTitle("你是中国人吗，你好");
//		curve.setyUnit("你是中国人吗，你好");
//		curve.setxUnit("abcdefghijklmnopqrstuvwxyz");
//		curve.setToolTipTextColor(Color.black);
//		curve.setToolTipTextFont(new Font("TimesRoman",Font.BOLD,16));
		curve.addCurveMouseListeners(new CurveMouseListener(){

			@Override
			public void mouseMoved(float x, float y) {
//				curve.setToolTipText(decimalFormat.format(x)+","+decimalFormat.format(y)+"\nabc");
//				curve.repaint();
			}

			@Override
			public void mouseDragged(float x, float y) {
//				curve.setToolTipText(decimalFormat.format(x)+","+decimalFormat.format(y)+"\nabc");
//				curve.repaint();
			}
			
		});
		
//		curve.setScaleXColor(Color.red);
//		curve.setScaleXFont(new Font("TimesRoman",Font.BOLD,14));
//		curve.setBackground(Color.white);
//		curve.setAxisYColor(Color.black);
//		curve.setAxisXColor(Color.black);
//		curve.setSelectAreaColor(Color.red);
		curve.getAxisX().setEnd(20000);
		curve.getAxisXCurrent().setEnd(20000);
		container.add(curve);
	
		lines1=new CurveLines();
		curve.addCurveListeners(lines1);
		lines2=new CurveLines();
		lines2.setColor(Color.blue);
		curve.addCurveListeners(lines2);
		
		new Thread(){
			public void run(){
//				while(true)
				{
//					long between = 0;
//			        Date begin=null;
//			        try {
//			            begin = new Date();
//			        } catch (Exception ex) {
//			            ex.printStackTrace();
//			        }
			        //数据模拟开始
					float[] data=new float[20000];
					for(int i=0;i<data.length;i++){
						data[i]=(float)(Math.random()*80);
					}
					lines1.setData(data);
					
					data=new float[20000];
					for(int i=0;i<data.length;i++){
//						data[i]=i;
						data[i]=(float)(Math.random()*80);
					}
					lines2.setData(data);
					
//					curve.getAxisX().setEnd(20000);
//					curve.getAxisXCurrent().setEnd(20000);
//					curve.getAxisY().setEnd(100);
//					curve.getAxisYCurrent().setEnd(100);
					
					curve.repaint();
					
//					try {
//			            Date end = new Date();
//			            between = (end.getTime() - begin.getTime());// 得到两者的毫秒数
//			            System.out.println(between);
//			        } catch (Exception ex) {
//			            ex.printStackTrace();
//			        }
			        
			        try {
						Thread.sleep(100);
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}
		}.start();
		
		container.add(curve);
		curve.setVisible(true);
		this.setVisible(true);
	}
}
